package com.zmm.weblog.admin.config;

import org.apache.tomcat.util.threads.ThreadPoolExecutor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * @Author: 福禄寿
 * @Date: 2024/8/22 下午2:55
 * @Des: weblog-springboot
 **/
@Configuration
@EnableAsync

public class ThreadPoolConfig {

    @Bean
    public ThreadPoolTaskExecutor threadPoolTaskExecutor(){
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(10);//核心线程数
        executor.setMaxPoolSize(20);//最大线程数
        executor.setQueueCapacity(100);//队列容量
        executor.setThreadNamePrefix("WeblogThreadPool-");//线程名称前缀
        executor.initialize();//初始化线程池
        return executor;
    }
}
